package com.foreverwin.jzymes.production.tool.controller;

import com.foreverwin.jzymes.common.mapper.ToolAdiviceMapper;
import com.foreverwin.jzymes.common.service.ISiteAdviceService;
import com.foreverwin.jzymes.common.util.BOHandleUtil;
import com.foreverwin.jzymes.common.util.CommonMethods;
import com.foreverwin.jzymes.framework.base.AjaxResult;
import com.foreverwin.jzymes.framework.exception.BusinessException;
import com.foreverwin.jzymes.framework.util.I18nUtil;
import com.foreverwin.jzymes.production.tool.domain.TOOL;
import com.foreverwin.jzymes.production.tool.domain.ToolBill;
import com.foreverwin.jzymes.production.tool.domain.ToolBillItem;
import com.foreverwin.jzymes.production.tool.mapper.TOOLMapper;
import com.foreverwin.jzymes.production.tool.service.ITOOLAdiviceService;
import com.foreverwin.jzymes.production.tool.service.ITOOLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/production/tool")
public class ToolController {
    @Autowired
    ITOOLAdiviceService itoolAdiviceService;
    @Autowired
    ITOOLService itoolService;
    @Autowired
    ISiteAdviceService siteAdviceService;
    @Autowired
    TOOLMapper toolMapper;
    @Autowired
    ToolAdiviceMapper toolAdiviceMapper;


    /**保存刀具*/
    @RequestMapping("/save")
    public AjaxResult saveTool(@RequestBody TOOL tool) {
        try{
            tool.setSite( CommonMethods.getSite() );
            //tool.setHandle( BOHandleUtil.buildToolHandle( tool.getSite() , tool.getToolType() ) );
            itoolAdiviceService.saveToolData( tool );
            return AjaxResult.returnSuccess().put("value",tool);
        }catch ( BusinessException e ){
            return AjaxResult.returnError( e.getMessage() );
        }
    }

    /**编辑刀具*/
    @RequestMapping("/edit")
    public AjaxResult editTool(@RequestBody TOOL tool) {
        try{
            tool.setSite( CommonMethods.getSite() );
            //tool.setHandle( BOHandleUtil.buildToolHandle( tool.getSite() , tool.getToolType() ) );
            itoolAdiviceService.editToolData( tool );
            return AjaxResult.returnSuccess().put("value",tool);
        }catch ( BusinessException e ){
            return AjaxResult.returnError( e.getMessage() );
        }
    }

    /**检索刀具*/
    @RequestMapping("/retrieve")
    public AjaxResult retrieve(@RequestParam Map<String,Object> jsonMap ) {

      List<TOOL> tools =  toolAdiviceMapper.selectToolByReport( (String) jsonMap.get("toolType") , CommonMethods.getSite() );

        return AjaxResult.returnSuccess().put( "value" , tools );
    }

    /**删除刀具信息*/
    @RequestMapping("/deteleTool")
    public AjaxResult deteleTool(@RequestBody List<String> list) {

        try{
            itoolAdiviceService.deteleToolData( list );
            return AjaxResult.returnSuccess();
        }catch ( BusinessException e ){
            return AjaxResult.returnError( e.getMessage() );
        }
    }
}
